<!--
 * @Author: xiaxia
 * @Description: 
 * @Date: 2024-06-28 15:08:46
 * @LastEditTime: 2024-07-01 14:09:12
 * @FilePath: \project\src\components\Category\index.vue
-->
<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类" prop="category1Id">
        <el-select
          v-model="categoryStore.category1Id"
          placeholder="请选择"
          style="width: 240px"
          @change="changeCate1"
          :disabled="isTable!=0"
        >
          <el-option
            v-for="item in categoryStore.options1"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" prop="category2Id">
        <el-select
          v-model="categoryStore.category2Id"
          placeholder="请选择"
          style="width: 240px"
          @change="changeCate2"
          :disabled="isTable!=0"
        >
        <el-option
          v-for="item in categoryStore.options2"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" prop="category1Id">
        <el-select
          v-model="categoryStore.category3Id"
          placeholder="请选择"
          style="width: 240px"
          :disabled="isTable!=0"
        >
          <el-option
            v-for="item in categoryStore.options3"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts" setup>
import {onMounted} from 'vue';
import useCategoryStore from '@/store/modules/category.ts'

const categoryStore = useCategoryStore() // store category
defineProps(['isTable'])

onMounted(()=>{
  // 获取一级分类
  categoryStore.getCate1()
})
// 一级分类 change
const changeCate1 = async (id:number)=> {
  categoryStore.category2Id = ''
  categoryStore.category3Id = ''
  categoryStore.options3 = []
  categoryStore.getCate2(id)
}
// 二级分类 change
const changeCate2 = async (id:number)=> {
  categoryStore.category3Id = ''
  categoryStore.getCate3(id)
}
</script>

<style lang="scss" scoped>

</style>